<template>
    <div></div>
</template>

<script>
import { reactive,toRefs,onBeforeMount,onMounted} from 'vue'
export default {
    name: '',
        setup() {
            console.log('1-开始创建组件-setup')
            const data = reactive({

            })
            const onScan=()=>{
                try {
                    QRScanner.show(status => {
                    console.log("[Scan.vue onScan] 显示扫描" + JSON.stringify(status));
                    });
                    //监听扫描结果
                    QRScanner.scan((err, contents) => {
                        alert("进入监听");
                        if (err) {
                            alert(JSON.stringify(e))
                        } else {
                            alert('扫描结果: ' + contents);
                        }
                    });
                } catch (e) {
                    alert("error")
                    console.log(QRScanner)
                    console.log("[Scan.vue：onScan] " + JSON.stringify(e))
                }
            }
            const refData = toRefs(data);
            onMounted(()=>{
                onScan()
            })
            return {
                onScan,
                ...refData,
            }
        }
};
</script>
<style scoped>
</style>